package com.inspur.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.inspur.system.dto.PmDemDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.inspur.common.annotation.Log;
import com.inspur.common.core.controller.BaseController;
import com.inspur.common.core.domain.AjaxResult;
import com.inspur.common.enums.BusinessType;
import com.inspur.system.domain.PmDem;
import com.inspur.system.service.IPmDemService;
import com.inspur.common.utils.poi.ExcelUtil;
import com.inspur.common.core.page.TableDataInfo;

/**
 * 【需求】Controller
 *
 * @author ruoyi
 * @date 2024-04-07
 */
@RestController
@RequestMapping("/system/dem")
public class PmDemController extends BaseController
{
    @Autowired
    private IPmDemService pmDemService;

    /**
     * 查询【需求】列表
     */
    @PreAuthorize("@ss.hasPermi('system:dem:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmDemDTO pmDem)
    {
        startPage();
        List<PmDemDTO> list = pmDemService.selectPmDemList(pmDem);
        return getDataTable(list);
    }

    /**
     * 查询需求数量
     */
    @PreAuthorize("@ss.hasPermi('system:dem:listnum')")
    @GetMapping("/listNum")
    public AjaxResult listNum()
    {
        return success(pmDemService.selectPmDemNum());
    }

    /**
     * 导出【需求】列表
     */
    @PreAuthorize("@ss.hasPermi('system:dem:export')")
    @Log(title = "【需求】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmDem pmDem)
    {
        List<PmDem> list = pmDemService.selectPmDemListExport(pmDem);
        ExcelUtil<PmDem> util = new ExcelUtil<PmDem>(PmDem.class);
        util.exportExcel(response, list, "【需求】数据");
    }

    /**
     * 获取【需求】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dem:query')")
    @GetMapping(value = "/{cDemNo}")
    public AjaxResult getInfo(@PathVariable("cDemNo") String cDemNo)
    {
        return success(pmDemService.selectPmDemByCDemNo(cDemNo));
    }

    /**
     * 新增【需求】
     */
    @PreAuthorize("@ss.hasPermi('system:dem:add')")
    @Log(title = "【新增需求】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmDem pmDem)
    {
        return toAjax(pmDemService.insertPmDem(pmDem));
    }

    /**
     * 修改【需求】
     */
    @PreAuthorize("@ss.hasPermi('system:dem:edit')")
    @Log(title = "【修改需求】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmDem pmDem)
    {
        return toAjax(pmDemService.updatePmDem(pmDem));
    }

    /**
     * 删除【需求】
     */
    @PreAuthorize("@ss.hasPermi('system:dem:remove')")
    @Log(title = "【删除需求】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cDemNos}")
    public AjaxResult remove(@PathVariable String[] cDemNos)
    {
        return toAjax(pmDemService.deletePmDemByCDemNos(cDemNos));
    }
}
